package com.booter.webflux.http.processor;

import com.booter.webflux.http.annotation.ServiceApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/***
 * z
 */
@Slf4j
@Component
public class ServiceCreateProcessor implements CreateProcessor {


    @Override
    public <T> Object create(Class<T> cls, Method method, Object[] args) {
        ServiceApi api = cls.getAnnotation(ServiceApi.class);
        String url = api.url();
        String name = api.name();
        Annotation[] mans = method.getAnnotations();
        System.out.println(mans);


        GetMapping gm = method.getDeclaredAnnotation(GetMapping.class);
        PostMapping pm = method.getDeclaredAnnotation(PostMapping.class);

        RequestMapping rm = method.getDeclaredAnnotation(RequestMapping.class);
        String uri = rm.value()[0];
        url = (url.endsWith("/") ? url : url.concat("/")).concat(uri.charAt(0) == '/' ? uri.substring(1) : uri);
        log.info("apiName:{},url:{}", name, url);
        return args[0] + " ok";
    }
}
